﻿using AutoMapper;
using Common.Communal;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Sell.Api.Write.Application.Command.ContractCommand;

namespace Sell.Api.Write.Controllers.Contracts
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ContractController : ControllerBase
    {
        public IMediator mediator {  get;}
        public ContractController(IMediator _mediator)
        {
            mediator= _mediator;
        }
        /// <summary>
        /// 添加采购合同
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> ContractAdd(ContractAddCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 删除采购合同
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<int>> ContractDel([FromQuery]ContractDelCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改采购合同
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> ContractUpdate([FromBody] ContractUpdateCommand request)
        {
            if (!ModelState.IsValid)
            {
                var result = new ApiResult<int>();
                result.Error("请求参数验证失败");
                return result;
            }
            return await mediator.Send(request);
        }
        /// <summary>
        /// 修改采购合同审核状态
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ApiResult<int>> ContractUpdateReviewStatus([FromBody] ContractUpdateReviewStatusCommand request)
        {
            if (!ModelState.IsValid)
            {
                var result = new ApiResult<int>();
                result.Error("请求参数验证失败");
                return result;
            }
            return await mediator.Send(request);
        }
    }
}
